home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 1.7 KB | 75 lines | [AMAS/AMAP] |
- // -* BlinkBehavior.js *-
- //
- // Name: Blink behavior
- // Description:
- // Author:
- // Version: $Id: BlinkBehavior.js,v 1.8 2000/12/21 15:03:30 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var blinkSolids = new Array(1);
-
- function BlinkBehavior(solidName, delay, geom)
- {
- // Member methods of the behavior
- this.start = BlinkBehaviorStart;
- this.stop = BlinkBehaviorStop;
-
- // Make a new timer
- this.timerId = TSMakeUniqID("Blink_" + solidName);
- this.geomId = geom;
- this.delay = delay;
-
- TSMakeTimerEvent(this.timerId, 0, delay, 'BlinkChangeState');
- TSSetExtraParam(this.timerId, 'geom', geom);
- TSAppendChild(solidName, this.timerId);
- TSUpdateNode(this.timerId);
- }
-
- function BlinkBehaviorStart()
- {
- TSUpdateNodeAttribute(this.timerId, 'every', this.delay.toString());
- }
-
- function BlinkBehaviorStop()
- {
- TSUpdateNodeAttribute(this.timerId, 'every', '65535');
- TSUpdateNodeAttribute(this.geomId, 'visible', '1');
- }
-
- function BlinkChangeState(obj, event)
- {
- var geom = TSGetExtraParam(event, 'geom');
-
- if (TSGetAttribute(geom, 'visible') == '1') {
- TSUpdateNodeAttribute(geom, 'visible', '0');
- } else {
- TSUpdateNodeAttribute(geom, 'visible', '1');
- }
- }
-
- //
- // Event functions
- //
-
- function BlinkBehaviorStartEvent(obj, event)
- {
- if (blinkSolids[obj] == null) {
- var delay = TSGetExtraParam(event, 'delay');
- var geom = TSGetExtraParam(event, 'geom');
- var targetSolid = TSGetExtraParam(event, 'targetSolid');
-
- if (targetSolid == "")
- blinkSolids[obj] = new BlinkBehavior(obj, delay, geom);
- else
- blinkSolids[obj] = new BlinkBehavior(targetSolid, delay, geom);
- }
-
- blinkSolids[obj].start();
- }
-
- function BlinkBehaviorStopEvent(obj, event)
- {
- blinkSolids[obj].stop();
- }
-